import logo from "./logo.svg";
import "./App.css";
import { useEffect, useState } from "react";

function App() {
  const [count, setCount] = useState(0);
  // 封装状态更新逻辑
  // const updateCount = () => {
  //   setCount(
  //     (prevCount) => prevCount + 1,
  //     () => {
  //       console.log("count", count);
  //     }
  //   );
  // };
  useEffect(() => {
    let _count = 0;
    setCount(
      (prevCount) => prevCount + 1,
      () => {
        console.log("count", count);
      }
    );
    // let interval = setInterval(() => {
    //   _count++;
    //   updateCount();
    //   if (_count >= 5) {
    //     clearInterval(interval);
    //   }
    // }, 1000);
    // return () => {
    //   clearInterval(interval);
    // };
  }, []);

  return (
    <div className="App">
      <header className="App-header">
        <img src={logo} className="App-logo" alt="logo" />
        <p>
          Edit <code>src/App.js</code> and save to reload.
        </p>
        <a
          className="App-link"
          href="https://reactjs.org"
          target="_blank"
          rel="noopener noreferrer"
        >
          {{ count }}
        </a>
      </header>
    </div>
  );
}

export default App;
